" .vimrc不再是一个文件，而是一个symbolic link。真正的.vimrc文件存储在stow根目录中。
"======================== Vundle Settings ======================================
set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/vimfiles/bundle/Vundle.vim/
call vundle#begin('~/vimfiles/bundle/')
" alternatively, pass a path where vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'Valloric/YouCompleteMe'
Plugin 'bling/vim-airline'
Plugin 'scrooloose/syntastic'
Plugin 'scrooloose/nerdtree'
" Plugin 'kien/ctrlp.vim'
" 使用unite.vim代替ctrlp等文件搜索工具
Plugin 'Shougo/unite.vim'
Plugin 'Shougo/vimproc.vim'
Plugin 'terryma/vim-multiple-cursors'
Plugin 'tpope/vim-surround'
"python-mode插件和youcompleteme不兼容，会导致自动补全卡死。
" Plugin 'klen/python-mode'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'majutsushi/tagbar'
Plugin 'SirVer/ultisnips'
Plugin 'scrooloose/nerdcommenter'
Plugin 'nathanaelkane/vim-indent-guides'
Plugin 'therubymug/vim-pyte'
Plugin 'tpope/vim-repeat'
Plugin 'fholgado/minibufexpl.vim'
Plugin 'vim-scripts/matchit.zip'
Plugin 'junegunn/vim-easy-align'
Plugin 'sjl/gundo.vim'
Plugin 'szw/vim-ctrlspace'
Plugin 'tpope/vim-unimpaired'
Plugin 'Raimondi/delimitMate'
Plugin 'altercation/vim-colors-solarized'
" ack命令搜索
Plugin 'mileszs/ack.vim'
" ack的替代品
Plugin 'rking/ag.vim'
Plugin 'pangloss/vim-javascript'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
Plugin 'L9'
Plugin 'mattn/emmet-vim'
"Plugin 'airblade/vim-gitgutter'
Plugin 'honza/vim-snippets'
"Plugin 'msanders/snipmate.vim'
Plugin 'godlygeek/tabular'
Plugin 'plasticboy/vim-markdown'
" 使用python编写vim-script
"Plugin 'amoffat/snake'
Plugin 'suan/vim-instant-markdown'
Plugin 'mhinz/vim-startify'
" vim对lua的支持
"Plugin 'xolox/vim-misc'
"Plugin 'xolox/vim-lua-ftplugin'
Plugin 'itchyny/calendar.vim'
" Plugin 'vim-scripts/luarefvim'
Plugin 'vim-scripts/VimIM' 
" Plugin 'vimim/vimim' 
" vim-script验证语法插件
"Plugin 'todesking/vint-Syntastic'

" All of your Plugins must be added before the following line
call vundle#end()            " required
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

"======================== Begin Settings ======================================
" An example for a vimrc file.
"
" Maintainer:	Bram Moolenaar <Bram@vim.org>
" Last change:	2011 Apr 15
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"	      for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"	    for OpenVMS:  sys$login:.vimrc

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? 'evim'
  finish
endif

" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

if has("vms")
  set nobackup		" do not keep a backup file, use versions instead
else
  set backup		" keep a backup file
endif
set history=50		" keep 50 lines of command line history
set ruler		" show the cursor position all the time
set showcmd		" display incomplete commands
set incsearch		" do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
"map Q gq

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
noremap <Leader>ch :nohlsearch<CR>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  " filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

else

  set autoindent		" always set autoindenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
		  \ | wincmd p | diffthis
endif

"======================== Custom Settings =======================================

" 支持对应语言的语法折叠
let g:vimsyn_folding = 'aftlpPr' 

noremap <C-J>     <C-W>j
noremap <C-K>     <C-W>k
noremap <C-H>     <C-W>h
noremap <C-L>     <C-W>l

noremap ;y "*y

let mapleader=";"
" 开启实时搜索功能
set incsearch
" 搜索时大小写不敏感
set ignorecase
"防止特殊字符号无法显示
set ambiwidth=double
"缩进尺寸为4个空格
set sw=4
"tab宽度为4个字符
set ts=4
"编辑时将所有tab替换为空格
set et
"按一次backspace就删除4个空格
set smarttab

" 禁止显示滚动条
set guioptions-=l
set guioptions-=L
set guioptions-=r
set guioptions-=R
" 禁止显示菜单和工具条
set guioptions-=m
set guioptions-=T
" 高亮显示当前行/列
set cursorline
set cursorcolumn

" 基于缩进或语法进行代码折叠
"set foldmethod=indent
set foldmethod=syntax
" 启动 vim 时进行折叠代码
set foldenable

" 设置编码
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
if has("win32")
  set fileencoding=chinese
else
  set fileencoding=utf-8
endif

"解决consle输出乱码
language messages zh_CN.utf-8

" 设置文件编码检测类型及支持格式
set fencs=utf-8,gbk,ucs-bom,gb18030,gb2312,cp936
" 指定菜单语言
set langmenu=zh_CN.utf-8
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim

" 设置中文帮助，必须包含“+multi_lang”属性
if version >= 603
	set helplang=cn
endif

winpos 300 0
set lines=90 columns=120
set nu
"set guifont=consolas:h10

set wrap

if v:version > 703 || v:version == 703 && has("patch541")
  set formatoptions+=j " Delete comment character when joining commented lines
endif
"======================== Indent-guides Settings ===============================

" 色块宽度
let g:indent_guides_guide_size = 1
let g:indent_guides_auto_colors = 0
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd  guibg=red   ctermbg=3
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=green ctermbg=4

"======================== Minibufexpl Settings =================================

noremap <C-TAB>   :MBEbn<CR>
noremap <C-S-TAB> :MBEbp<CR>
noremap <leader>bd :MBEbd!

let g:miniBufExplCycleArround = 1
" MiniBufExpl Colors
hi MBENormal               guifg=#808080 guibg=fg
hi MBEChanged              guifg=#CD5907 guibg=fg
hi MBEVisibleNormal        guifg=#5DC2D6 guibg=fg
hi MBEVisibleChanged       guifg=#F1266F guibg=fg
hi MBEVisibleActiveNormal  guifg=#A6DB29 guibg=fg
hi MBEVisibleActiveChanged guifg=#F1266F guibg=fg

"======================== Gundo Settings =======================================
" 开启保存 undo 历史功能
set undofile
" undo 历史保存路径
set undodir=$home/vimfiles/undo_history

" ===================== Tagbar Settings ======================================

" 设置显示／隐藏标签列表子窗口的快捷键。速记：tag list 
nnoremap <Leader>tl :TagbarToggle<CR> 
" 设置标签子窗口的宽度 
" let tagbar_width=32 
" tagbar 子窗口中不显示冗余帮助信息 
let g:tagbar_compact=1
" 设置 ctags 对哪些代码元素生成标签
let g:tagbar_type_cpp = {
    \ 'kinds' : [
        \ 'd:macros:1',
        \ 'g:enums',
        \ 't:typedefs:0:0',
        \ 'e:enumerators:0:0',
        \ 'n:namespaces',
        \ 'c:classes',
        \ 's:structs',
        \ 'u:unions',
        \ 'f:functions',
        \ 'm:members:0:0',
        \ 'v:global:0:0',
        \ 'x:external:0:0',
        \ 'l:local:0:0'
     \ ],
     \ 'sro'        : '::',
     \ 'kind2scope' : {
         \ 'g' : 'enum',
         \ 'n' : 'namespace',
         \ 'c' : 'class',
         \ 's' : 'struct',
         \ 'u' : 'union'
     \ },
     \ 'scope2kind' : {
         \ 'enum'      : 'g',
         \ 'namespace' : 'n',
         \ 'class'     : 'c',
         \ 'struct'    : 's',
         \ 'union'     : 'u'
     \ }
\ }
let g:tagbar_show_linenumbers = -1
let g:tagbar_expand = 1
let g:tagbar_zoomwidth = 0

"======================== Ctrlspace Settings ===================================

set hidden

"======================== Airline Settings =====================================
let g:airline_detect_paste=1
" 设置为始终显示状态栏
set laststatus=2

"======================== Nerdtree Settings ====================================
nnoremap <leader>nt :NERDTreeToggle<CR>:call ToggleNTree()<CR> 
let NERDTreeShowHidden=1
let NERDTreeShowLineNumbers=1
let NERDTreeWinSize=50

let isNERDTree=0
function! ToggleNTree()
    let posX=getwinposx()
    if g:isNERDTree==1
        let g:isNERDTree=0
        execute "winpos" posX+300 0
        set columns-=50
    else
        let g:isNERDTree=1
        execute "winpos" posX-300 0
        set columns+=50
    endif
endfunction

"======================== Color Settings =======================================
if has('gui_running')
    set background=light
else
    set background=dark
endif

colorscheme solarized
"set nocolorcolumn

hi CursorColumn ctermbg=7 guibg=#ddd8d5
hi CursorLine cterm=underline guibg=#ddd8d5 guisp=#586e75 

"======================== Unite Settings =======================================
call unite#filters#matcher_default#use(['matcher_fuzzy'])
nnoremap <leader>fu :<C-u>Unite -start-insert file_rec/async:!<CR>
nnoremap <leader>ff :<C-u>Unite -start-insert file<CR>
let g:unite_source_rec_async_command =
        \ ['ag', '--follow', '--nocolor', '--nogroup',
        \  '--hidden', '-g', '']
let g:unite_data_directory = 'D:\00Data\Config\vim\windows\unite'

"======================== delimitMate Settings =================================


"======================== UltiSnips Settings =================================== 
let g:UltiSnipsExpandTrigger="<c-c>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"

"======================== Markdown Settings ==================================== 
"autocmd BufNewFile,BufReadPost *.md set filetype=markdown
"set shell=bash\ -i

"======================== Syntastic Settings ===================================
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_error_symbol = "✗"
let g:syntastic_warning_symbol = "⚠"
let g:syntastic_style_error_symbol = "S✗"
let g:syntastic_style_warning_symbol = "S!"
let g:syntastic_python_flake8_args = '--max-line-length 5000'

noremap <leader>ln :lnext<CR>

"======================== Startify Settings ====================================
let g:startify_bookmarks = [ {'v': '~/.vimrc'}, {'b': '~/.vim/bundle/'}, {'w': 'D:\Workspace\'}, {'a': 'D:\01Personal\00accounts'} ]
noremap <leader>mn :Startify<CR>

"======================== VimIM Settings =======================================
"let g:Vimim_map = 'tab_as_onekey'   
let g:Vimim_mode = 'static'
"let g:Vimim_cloud = -1
"let g:Vimim_toggle = 'pinyin' 

"======================== Vint Settings ========================================
"let g:syntastic_vim_checkers = ['vint']
